<?php namespace Home\Controller; 
use Hdphp\Controller\Controller;
/**
 *  首页
 */
class IndexController extends Controller{
    	//显示页
    	public function index(){
	 	$arcModel = new \Common\Model\Article();
	 	$category = new \Common\Model\Category();
	 	$arcTagModel = new \Common\Model\ArticleTag();
	 	$tagModel = new \Common\Model\Tag();
		 	
		//查出没有被回收的所有文章
		$data = array();
		$field = "aid, author,sendtime,imgs,digest,title,click";
		//总计总数
		$total = $arcModel->where("is_recycle=0")->count();
		//定制分页样式
		$page = Page::row(4)->desc(array('pre'=>'← Previous', 'next'=>'Next → '))->make($total);
		//获取文章数据
		$articleData = $arcModel->join('category','category_cid','=','cid')->field($field)->where("is_recycle=0")->limit(Page::limit())->orderBy('sendtime','DESC')->get();
		if ($articleData) {
			foreach ($articleData as  $v) {
				$v['tag'] = $arcTagModel->join('tag','tag_tid','=','tid')->where(array('article_aid'=>$v['aid']))->lists('tid,tname');
				$data[] = $v;
			}
		}
		$this->assign('page', $page);
		$this->assign('total', $total);
		$this->assign('data',$data);
    		$this->display();
    	}
    	
    	
    	
}
